package org.sanguine.plugin.timetracker.providers;

import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 *     Factory for service provider of Tracking service
 * </p>
 * <p>
 * </p>
 * <b>Date:</b> 13.10.2014
 *
 * @author Alexey_Kuznetsov
 */
public class TrackerServiceProviderFactory {
    private final static Map<String, TrackerServiceProvider> providers;

    static {
        Map<String, TrackerServiceProvider> map = new HashMap<>(1);
        map.put("HARVEST", HarvestServiceProvider.getInstance());

        providers = Collections.unmodifiableMap(map);
    }

    /**
     * Returns Tracker Service provider for given name
     *
     * @param providerName
     *              Name of provider
     * @return TrackerServiceProvider instance
     *
     * @throws java.lang.IllegalArgumentException if providerName is null or empty
     * @throws java.lang.UnsupportedOperationException if provider with given name is not implemented
     *
     */
    public static TrackerServiceProvider getProvider(String providerName) {
        if (providerName == null || providerName.isEmpty()) throw new IllegalArgumentException("providerName must be given");

        TrackerServiceProvider provider = providers.get(providerName);

        if (provider == null) throw new UnsupportedOperationException("Provider " + providerName + " is not implemented");

        return provider;
    }

    /**
     * Get known providers
     * @return Known providers list
     */
    public static Collection<String> getProviders() {
        return providers.keySet();
    }
}
